﻿using OpenTK;
using OpenTK.Graphics.OpenGL4;
using System;
using System.Runtime.InteropServices;

namespace Painter3D.RenderSys.Tool
{
    static class GraphicsTool
    {
        [Obsolete]
        public static void SetUpVertByDefaultXYZ(float[] vertex, out int VBO, out int VAO)
        {
            VBO = GL.GenBuffer();
            VAO = GL.GenVertexArray();
            GL.BindVertexArray(VAO);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VBO);
            GL.BufferData(BufferTarget.ArrayBuffer, vertex.Length * sizeof(float), vertex, BufferUsageHint.StaticDraw);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, true, 3 * sizeof(float), 0);
            GL.EnableVertexAttribArray(0);
        }
        [Obsolete]
        public static void ResetVert(int VBO, int VAO)
        {
            GL.DeleteBuffer(VBO);
            GL.DeleteVertexArray(VAO);
        }
        [Obsolete]
        public static void SetUpUBO(out int UBO, int point)
        {
            UBO = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.UniformBuffer, UBO);
            GL.BufferData(BufferTarget.UniformBuffer, 64, (IntPtr)null, BufferUsageHint.DynamicDraw);
            GL.BindBuffer(BufferTarget.UniformBuffer, 0);
            GL.BindBufferRange(BufferRangeTarget.UniformBuffer, point, UBO, (IntPtr)0, 64);
        }
        [Obsolete]
        public static void UploadCameraMat(Matrix4 camera, int UBO)
        {
            GL.BindBuffer(BufferTarget.UniformBuffer, UBO);
            GL.BufferSubData(BufferTarget.UniformBuffer, (IntPtr)0, 64, ref camera);
            GL.BindBuffer(BufferTarget.UniformBuffer, 0);
        }
        [Obsolete]
        public static void ResetUBO(int UBO)
        {
            GL.DeleteBuffer(UBO);
        }
    }
}
